﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using WWLauncher.Constant;
using WWLauncher.Startup;
using WWLauncher.Util;
using WWLauncher.View.Other;
using static System.Windows.Forms.LinkLabel;

namespace WWLauncher.ViewModel
{
    public class IconViewModel : INotifyPropertyChanged
    {
        private byte[] imageByteArr;
        private string targetPath;
        private string lnkPath;
        private string name;
        private string startArg;
        private string relativePath;
        private byte[] defaultImageArr;
        private BitmapImage bitmapImage;
        private bool adminStartUp;
        private Guid id;
        private bool startup;

        public Guid Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
                OnPropertyChanged(nameof(Id));
            }
        }
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }


        public string LnkPath
        {
            get
            {
                return lnkPath;
            }
            set
            {
                lnkPath = value;
                OnPropertyChanged("LnkPath");
            }
        }


        public string StartArg
        {
            get
            {
                return startArg;
            }
            set
            {
                startArg = value;
                OnPropertyChanged("StartArg");
            }
        }


        public string TargetPath
        {
            get
            {
                return targetPath;
            }
            set
            {
                targetPath = value;
                OnPropertyChanged("TargetPath");
            }
        }

        public Guid LinkId
        {
            get
            {
                return linkId;
            }
            set
            {
                linkId = value;
                OnPropertyChanged(nameof(LinkId));
            }
        }

        public string RelativePath
        {
            get
            {
                return relativePath;
            }
            set
            {
                relativePath = value;
                OnPropertyChanged("RelativePath");
            }
        }


        public byte[] DefaultImageArr
        {
            get
            {
                return defaultImageArr;
            }
            set
            {
                defaultImageArr = value;
            }
        }

        public BitmapImage BitmapImage
        {
            get
            {
                return ImageUtil.ByteArrToImage(ImageByteArr);
            }
            set
            {
                bitmapImage = value;
                ImageByteArr = ImageUtil.BitmapImageToByte(bitmapImage);
                OnPropertyChanged("BitmapImage");
            }
        }


        public byte[] ImageByteArr
        {
            get
            {
                return imageByteArr;
            }
            set
            {
                imageByteArr = value;
                OnPropertyChanged("ImageByteArr");
            }
        }

        public string ToolTip { get; set; }


        public IconStartType StartType { get; set; }

        public bool AdminStartUp
        {
            get
            {
                adminStartUp = StartType == IconStartType.AdminStartUp;
                return adminStartUp;
            }
            set
            {
                adminStartUp = value;
                StartType = adminStartUp ? IconStartType.AdminStartUp : IconStartType.DefaultStartup;

                OnPropertyChanged("AdminStartUp");
            }
        }
        public bool IsStartup
        {
            get => startup;
            set
            {
                startup = value;
                OnPropertyChanged(nameof(IsStartup));
            }
        }
        private ComplexInfoModel comboboxItem;
        private ObservableCollection<ComplexInfoModel> comboboxList;
        private Guid linkId;

        /// <summary>
        /// 下拉框选中信息
        /// </summary>
        public ComplexInfoModel ComboboxItem
        {
            get { return comboboxItem; }
            set { comboboxItem = value; OnPropertyChanged(nameof(ComboboxItem)); }
        }
        public ObservableCollection<ComplexInfoModel> ComboboxList
        {
            get => comboboxList;
            set
            {
                comboboxList = value;
                OnPropertyChanged(nameof(ComboboxList));
            }
        }
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
